$OpenBSD: patch-lsdvd_c,v 1.7 2015/05/02 19:58:47 ajacoutot Exp $
--- lsdvd.c.orig	Sat Oct  4 07:09:14 2014
+++ lsdvd.c	Sat May  2 21:56:45 2015
@@ -21,6 +21,7 @@
 #include <unistd.h>
 #include <getopt.h>
 #include <dvdread/ifo_read.h>
+#include <dvdread/ifo_print.h>
 #include "lsdvd.h"
 #include "ocode.h"
 
@@ -122,6 +123,7 @@ static void converttime(playback_time_t *pt, dvd_time_
 
 /*
  *  The following method is based on code from vobcopy, by Robos, with thanks.
+ *  It fails opening a directory (like /home/movies/casablanca/VIDEO_TS/)
  */
 static int get_title_name(const char* dvd_device, char* title)
 {
@@ -133,20 +135,28 @@ static int get_title_name(const char* dvd_device, char
 		strcpy(title, "unknown");
 		return -1;
 	}
+	fprintf(stderr, "opening %s for title\n", dvd_device);
 
-	if ( fseek(filehandle, 32808, SEEK_SET )) {
+	if ( fseek(filehandle, 32768, SEEK_SET )) {
 		fclose(filehandle);
 		fprintf(stderr, "Couldn't seek in %s for title\n", dvd_device);
 		strcpy(title, "unknown");
 		return -1;
 	}
 
-	if ( 32 != (i = fread(title, 1, 32, filehandle)) ) {
+	{
+	#define DVD_SEC_SIZ 2048
+	char tempBuf[ DVD_SEC_SIZ ];
+
+	if ( DVD_SEC_SIZ != fread(tempBuf, 1, DVD_SEC_SIZ, filehandle) ) {
 		fclose(filehandle);
 		fprintf(stderr, "Couldn't read enough bytes for title.\n");
 		strcpy(title, "unknown");
 		return -1;
 	}
+	snprintf( title, 32, "%s", tempBuf + 40 );
+	i=32;
+	}
 
 	fclose (filehandle);
 
@@ -199,7 +209,7 @@ static void usage(void)
 	fprintf(stderr, "\n");
 }
 
-int opt_a=0, opt_c=0, opt_n=0, opt_p=0, opt_q=0, opt_s=0, opt_t=0, opt_v=0, opt_x=0, opt_d=0, opt_P=0;
+int opt_a=0, opt_c=0, opt_m=0, opt_n=0, opt_p=0, opt_q=0, opt_s=0, opt_t=0, opt_v=0, opt_x=0, opt_d=0, opt_P=0;
 char opt_O='h';
 
 static char output_option(char *arg)
@@ -238,7 +248,7 @@ int main(int argc, char *argv[])
 	pgc_t *pgc;
 	int i, j, k, c, titles, cell, vts_ttn, title_set_nr;
  	char lang_code[3];
-	char *dvd_device = "/dev/dvd";
+	char *dvd_device = "/dev/rcd0c";
 	int has_title = 0, ret = 0;
 	int max_length = 0, max_track = 0;
 	struct stat dvd_stat;
@@ -255,18 +265,20 @@ int main(int argc, char *argv[])
 		case 's':	opt_s = 1;		break;
 		case 'q':	opt_q = 1;		break;
 		case 'c':	opt_c = 1;		break;
+		case 'm':	opt_m = 1;		break;
 		case 'n':	opt_n = 1;		break;
 		case 'p':	opt_p = 1;		break;
 		case 'P':	opt_P = 1;		break;
 		case 't':	opt_t = atoi(optarg);	break;
 		case 'O':	opt_O = output_option(optarg);	break;
-		case 'v':	opt_v = 1;		break;
+		case 'v':	opt_v++;		break;
 		case 'x':	opt_x = 1;
 				opt_a = 1;
 				opt_c = 1;
 				opt_s = 1;
 				opt_P = 1;
 				opt_d = 1;
+				opt_m = 1;
 				opt_n = 1;
 				opt_v = 1;		break;
 		}
@@ -280,6 +292,9 @@ int main(int argc, char *argv[])
 		return 1;
 	}
 
+	/* On at least NetBSD this fails if called after DVDOpen */
+	has_title = get_title_name(dvd_device, title);
+
 	dvd = DVDOpen(dvd_device);
 	if( !dvd ) {
 		fprintf( stderr, "Can't open disc %s!\n", dvd_device);
@@ -290,6 +305,12 @@ int main(int argc, char *argv[])
 		fprintf( stderr, "Can't open main ifo!\n");
 		return 3;
 	}
+	if (opt_v > 2) {
+		printf("Title 0 IFO dump\n");
+		printf("================\n");
+		ifo_print(dvd, 0);
+		printf("\n");
+	}
 
 	ifo = (ifo_handle_t **)malloc((ifo_zero->vts_atrt->nr_of_vtss + 1) * sizeof(ifo_handle_t *));
 
@@ -299,6 +320,12 @@ int main(int argc, char *argv[])
 			fprintf( stderr, "Can't open ifo %d!\n", i);
 			return 4;
 		}
+		if (opt_v > 2) {
+			printf("Title %2d IFO dump\n", i);
+			printf("=================\n");
+			ifo_print(dvd, i);
+			printf("\n");
+		}
 	}
 
 	titles = ifo_zero->tt_srpt->nr_of_srpts;
@@ -308,8 +335,6 @@ int main(int argc, char *argv[])
 		return 5;
 	}
 
-	has_title = get_title_name(dvd_device, title);
-
 	vmgi_mat = ifo_zero->vmgi_mat;
 
 	struct dvd_info dvd_info;
@@ -404,6 +429,11 @@ int main(int argc, char *argv[])
 					dvd_info.titles[j].angle_count = ifo_zero->tt_srpt->title[j].nr_of_angles;
 				} else {
 					dvd_info.titles[j].angle_count = 0;
+				}
+
+				// MENU STRUCTURE
+				if (opt_m) {
+					// void ifo_print(dvd_reader_t *, int);
 				}
 
 				/* AUDIO */
